<?php

namespace App\Repos;

use App\Models\Coupon;

class CouponRepo 
{
    public static function getList($where=[])
    {
        //dd($where);
        $data = Coupon::where($where)->get();

        return $data;
    }

    public static function save($data)
    {
    	$rs['status'] = true;
    	try {
    		$flag = Coupon::create($data);	
            $rs['data'] = $flag;
    	} catch (\Exception $e) {
    		$rs['status'] = false;
    		$rs['msg'] = $e->getMessage();
    		return $rs;
    	}    	
    	return $rs;
    }

    public static function delete($id)
    {
        $rs['status'] = true;
        try {
            $flag = Coupon::where(['id'=>$id])->delete();  
        } catch (\Exception $e) {
            $rs['status'] = false;
            $rs['msg'] = $e->getMessage();
            return $rs;
        }       
        return $rs;
    }

    public static function find($where)
    {
        return Coupon::where($where)->first();
    }

    public static function randomOne($where)
    {
        return Coupon::query()->where($where)->inRandomOrder()->first();
    }
}
